#ifndef LAYER_H
#define LAYER_H

#include <QObject>
#include <QDebug>
#include <QPainter>
#include <QMouseEvent>

#include "mapadapter.h"
#include "layermanager.h"
#include "geometry.h"
#include "point.h"

#include "wmsmapadapter.h"
#include "tilemapadapter.h"

class Layer : public QObject
{
    Q_OBJECT

public:
    friend class LayerManager;

    enum LayerType
    {
        MapLayer,
        GeometryLayer
    };

    Layer(QString layername, MapAdapter* mapadapter, enum LayerType layertype, bool takeevents=true);
    virtual ~Layer();

    QString	layername() const;

    const MapAdapter* mapadapter() const;

    void addGeometry(Geometry* geometry);

    void removeGeometry(Geometry* geometry);

    void clearGeometries();

    bool isVisible() const;

    Layer::LayerType layertype() const;

    void setMapAdapter(MapAdapter* mapadapter);

    Layer& operator=(const Layer& rhs);
    Layer(const Layer& old);

private:
    void moveWidgets(const QPoint mapmiddle_px) const;
    void drawYourImage(QPainter* painter, const QPoint mapmiddle_px) const;
    void drawYourGeometries(QPainter* painter, const QPoint mapmiddle_px, QRect viewport) const;
    void setSize(QSize size);
    QRect offscreenViewport() const;
    bool takesMouseEvents() const;
    void mouseEvent(const QMouseEvent*, const QPoint mapmiddle_px);
    void zoomIn() const;
    void zoomOut() const;
    void _draw(QPainter* painter, const QPoint mapmiddle_px) const;

    bool visible;
    QString mylayername;
    LayerType mylayertype;
    QSize size;
    QPoint screenmiddle;

    QList<Geometry*> geometries;
    MapAdapter* mapAdapter;
    bool takeevents;
    mutable QRect myoffscreenViewport;

signals:
    void geometryClicked(Geometry* geometry, QPoint point);

    void updateRequest(QRectF rect);
    void updateRequest();

public slots:
    void setVisible(bool visible);

};

#endif
